﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Microsoft.Practices.Unity;
using Vit.Web.Services;

namespace Vit.Web.DataAnnotations
{
    [AttributeUsage(AttributeTargets.Event | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Class)]
    public class DisplayNameAttribute : System.ComponentModel.DisplayNameAttribute
    {
        public DisplayNameAttribute(string displayName)
        {
            IUnityContainer unity = ((VitApplication)HttpContext.Current.ApplicationInstance).UnityContainer;
            ILocalizationService localize = unity.Resolve<ILocalizationService>();
            if (localize != null)
                this.DisplayNameValue = localize.Resource(Area, displayName);
            else
                this.DisplayNameValue = displayName;
        }

        public string Area { get; set; }
    }
}
